import { _decorator, Component, director, Node, sys, tween, v3 } from 'cc';
import { PrefsManager } from '../AshFramework/Managers/PrefsManager';
import { ZTool } from '../AshFramework/Utils/ZTool';
import { GameData } from './GameData';
import { WEAPON } from '../AshFramework/Datas/Constant';
import { AudioManager, Audios } from '../AshFramework/Managers/AudioManager';
import Banner from '../Banner';
import { TLWLSJ_UIManager } from './UIManager';
import { TLWLSJ_Panel } from './Panel';
import { Panel, UIManager } from '../AshFramework/Managers/UIManager';
const { ccclass, property } = _decorator;

@ccclass('MenuManager')
export class MenuManager extends Component {
    @property(Node)
    newGamePanel: Node = null;

    @property(Node)
    LoadPanel: Node = null;

    protected onLoad(): void {
        Banner.Instance.StartBannerPopupAd();
        Banner.Instance.StartPopupAd();
    }

    protected start(): void {
        AudioManager.PlayMusic(Audios.BGM);
    }

    newGameBtn() {
        AudioManager.PlaySound(Audios.ButtonClick);
        this.newGamePanel.active = true;
    }

    goOnBtn() {
        AudioManager.PlaySound(Audios.ButtonClick);
        this.LoadPanel.active = true;
        PrefsManager.Instance.userData.AllWeapon.forEach(e => {
            ZTool.GetEnumKeyByValue(WEAPON, e);
            GameData.addWeaponByType(e);
        })
        director.loadScene("Game");
    }

    startNewGame() {
        AudioManager.PlaySound(Audios.ButtonClick);
        this.LoadPanel.active = true;
        sys.localStorage.removeItem("TLWLSJ_GAMEDATA");
        sys.localStorage.removeItem("TLWLSJ_USERData");
        PrefsManager.Instance.userData.AllWeapon.forEach(e => {
            ZTool.GetEnumKeyByValue(WEAPON, e);
            GameData.addWeaponByType(e);
        })
        director.loadScene("Game");

    }

    closeNewGameBtn() {
        AudioManager.PlaySound(Audios.ButtonClick);
        this.close(this.newGamePanel);
    }

    close(panel: Node) {
        panel.getComponent(TLWLSJ_Panel).close(() => {
            panel.active = false;
        });
    }

    privacy() {
        UIManager.GetInstance().ShowPanel(Panel.PrivacyPanel);
    }
}


